package com.example.demo.mapper;

import com.example.demo.domain.entity.TrainHomework;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

/**
* @author DaoJia
* @description 针对表【train_homework(培训系统-作业)】的数据库操作Mapper
* @createDate 2024-02-04 23:06:21
* @Entity com.example.demo.domain.entity.TrainHomework
*/
public interface TrainHomeworkMapper extends BaseMapper<TrainHomework> {


    List<TrainHomework> getAssignedHomeworkForClass(@Param("classId") Long classId, @Param("status")Integer status, @Param("offset") int offset, @Param("limit") int limit);


    long getAssignedHomeworkCountForClass(@Param("classId")Long classId, @Param("status")Integer status);


    Long countPageByClassId(@Param("classId")Long classId);


    List<TrainHomework> getAllAssignedHomework(@Param("classId")Long classId, @Param("status")Integer status);

    @Select("SELECT count(*)\n" +
            "        FROM train_class_homework tch\n" +
            "                 JOIN train_homework th ON tch.homework_id = th.id\n" +
            "        WHERE tch.class_id = #{classId} AND th.status = #{status} AND th.end_time <= #{endTime};")
    long queryHomeWorkleCount(@Param("classId")Long trainClassId, @Param("status")Integer key, @Param("endTime") Date date);

    @Select("SELECT th.*\n" +
            "        FROM train_class_homework tch\n" +
            "                 JOIN train_homework th ON tch.homework_id = th.id\n" +
            "        WHERE tch.class_id = #{classId} AND th.status = #{status} AND th.end_time <= #{endTime} limit #{offset}, #{pageSize};")
    List<TrainHomework> queryHomeWorkle(@Param("classId")Long trainClassId, @Param("status")Integer key, @Param("endTime")Date date, @Param("offset") Integer offset, @Param("pageSize")Integer pageSize);

    @Select("SELECT count(*)\n" +
            "        FROM train_class_homework tch\n" +
            "                 JOIN train_homework th ON tch.homework_id = th.id\n" +
            "        WHERE tch.class_id = #{classId} AND th.status = #{status} AND th.end_time >= #{endTime};")
    long queryHomeWorkGeCount(@Param("classId")Long trainClassId, @Param("status")Integer key, @Param("endTime")Date date);

    @Select("SELECT th.*\n" +
            "        FROM train_class_homework tch\n" +
            "                 JOIN train_homework th ON tch.homework_id = th.id\n" +
            "        WHERE tch.class_id = #{classId} AND th.status = #{status} AND th.end_time >= #{endTime} limit #{offset}, #{pageSize};")
    List<TrainHomework> queryHomeWorkGe(@Param("classId")Long trainClassId, @Param("status")Integer key, @Param("endTime")Date date ,@Param("offset") Integer offset, @Param("pageSize")Integer pageSize);

    @Select("SELECT count(*)\n" +
            "        FROM train_class_homework tch\n" +
            "                 JOIN train_homework th ON tch.homework_id = th.id\n" +
            "        WHERE tch.class_id = #{classId} AND th.status = #{status} ;")
    long queryHomeWorkCount(@Param("classId")Long trainClassId, @Param("status")Integer key);

    @Select("SELECT th.*\n" +
            "        FROM train_class_homework tch\n" +
            "                 JOIN train_homework th ON tch.homework_id = th.id\n" +
            "        WHERE tch.class_id = #{classId} AND th.status = #{status} limit #{offset}, #{pageSize};")
    List<TrainHomework> queryHomeWork(@Param("classId")Long trainClassId, @Param("status")Integer key ,@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);
}




